<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="favicon.ico">
    <link rel="Shortcut Icon" href="favicon.ico"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <title>平台管理系统</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <style>
        .colorhuang, .qiagcolor:hover {
            color: #f79d3c;
        }

        .editThis, .updateThis, .updatePassword {
            border: 1px solid #fff;
        }

        .operation button {
            margin: 3px;
        }

        .xingdx {
            background-color: #f9f9f9;
        }

        tr td {
            text-align: center !important;
        }
        tr th{text-align:center!important;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-form">
                    <%-- 数据展示 --%>
                    <table class="layui-table" id="data-table" lay-filter="data-table">
                    </table>
                        <script type="text/html" id="toolbar">
                            {{# if(d.status == 0){ }}
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="send">发放</a>
                            {{# } }}
                        </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'table'], function () {
        var $ = layui.$, layer = layui.layer, admin = layui.admin, form = layui.form,
            element = layui.element, table = layui.table;
        form.render('select');
        element.render();

        table.render({
            elem: '#data-table',
            url: '/account/queryDealData',
            page: true,
            request: {
                pageName: 'current', //页码的参数名称，默认：page
                limitName: 'size' //每页数据量的参数名，默认：limit
            },
            cols: [[
                {field: 'id', title: 'ID', width: 100},
                {field: 'createTime', title: '日期', minWidth: 150,sort:true,
                    templet:"<div>{{layui.util.toDateString(d.createTime,'yyyy年MM月dd日')}}</div>"},
                {field: 'sendTotalDonate', title: '总贡献值', width: 150},
                {field: 'totalCal', title: '有效贡献值', width: 150,style:'color:red;font-weight:bold'},
                {field: 'unitCal', title: '贡献单元数', minWidth: 120,style:'color:#4a9ef8;font-weight:bold'},
                {field: 'unitReal', title: '单元共享值 <span style="font-weight:bold;">(输入)</span>', minWidth: 120,style:'color:#4a9ef8;font-weight:bold'},
                {field: 'unitTotal', title: '共享总值', minWidth: 120,style:'color:#4a9ef8;font-weight:bold'},
                {title: '操作', templet: '#toolbar',width:120}
            ]],
            skin: "row",
            even: true,
            size: "lg"
        });


        var active = {
            edit: function (id) {
                layer.open({
                    title: '设置数据',
                    type: 2,
                    area: ['550px', '460px'],
                    content: '/account/dealDataEdit?id=' + id
                });
            },
            send:function(id){
                layer.confirm('确定发放吗？', function(){
                    var iii = layer.load(1, {
                        shade: [0.1,'#fff']
                    });
                    $(".layui-btn").attr("disabled",true);
                    $.ajax({
                        url: '/account/handleSendDealData',
                        data: {"id":id},
                        success: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('data-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                                $(".layui-btn").attr("disabled",false);
                            }
                            layer.close(iii);
                        }
                    });
                });
            }
        };

        //监听事件
        table.on('tool(data-table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') {
                //编辑库存
                active[layEvent] && active[layEvent].call(this, data.id);
            }else if(layEvent === 'send'){
                active[layEvent] && active[layEvent].call(this,data.id);
            }
        });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('data-table', {
                where: field
            });
        });

    });
</script>
</body>
</html>